package com.xxx.management.web.controller;


import com.xxx.common.base.bo.ListResult;
import com.xxx.management.web.util.R;
import com.xxx.user.api.RoleApi;
import com.xxx.user.dto.RoleCreateReqDTO;
import com.xxx.user.dto.RoleGetAllReqDTO;
import com.xxx.user.dto.RoleGetAllResDTO;
import com.xxx.user.dto.RoleUpdateReqDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@AllArgsConstructor
public class RoleController {

    private final RoleApi roleApi;

    /**
     * 创建角色
     */
    @PostMapping("/v1/role/create")
    public R<String> create(@RequestBody RoleCreateReqDTO param) {
        return R.ok(roleApi.create(param));
    }

    /**
     * 更新角色
     */
    @PutMapping("/v1/role/update")
    public R<String> update(@RequestBody RoleUpdateReqDTO param) {
        return R.ok(roleApi.update(param));
    }

    /**
     * 删除角色
     */
    @DeleteMapping("/v1/role/delete")
    public R<String> delete(@RequestBody List<Long> ids) {
        return R.ok(roleApi.delete(ids));
    }

    /**
     * 获取角色数据
     */
    @GetMapping("/v1/role/getAll")
    public R<ListResult<RoleGetAllResDTO>> getAll(@SpringQueryMap RoleGetAllReqDTO param) {
        return R.ok(roleApi.getAll(param));
    }

}
